﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using YWTSSys.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using YWTSSys.Model;

namespace YWTSSys.DAL
{
    public class SLogDAL
    {
        /// <summary>
        /// 日志系统连接字符串
        /// </summary>
        protected static string ConnectionString
        {
            get
            {
                return "LogSysConnectionString";
            }
        }

        public static int Add(SLogInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase(ConnectionString);

            DbCommand dbCommand = DB.GetStoredProcCommand("SLog_Add", obj.LogType, obj.DWZRef, obj.RealName, obj.OpType, obj.OpOldObj, obj.OpNewObj);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static IDataReader GetList(int id)
	    {
            Database DB = DatabaseFactory.CreateDatabase(ConnectionString);		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("SLog_GetList", id);
            return DB.ExecuteReader(dbCommand);
	    }
        public static DataTable GetPagination(string SqlWhere, int PageIndex, int PageSize, string Sort, ref int TotalCount)
	    {
            Database DB = DatabaseFactory.CreateDatabase(ConnectionString);		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("SLog_GetPagination");
            DB.AddInParameter(dbCommand, "SqlWhere", DbType.String,SqlWhere);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32,PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32,PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String,Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32,8);
			DataTable dt=  DB.ExecuteDataSet(dbCommand).Tables[0];
				
            TotalCount=Convert.ToInt32( DB.GetParameterValue(dbCommand,"TotalCount"));
            return dt;
	    }
    }
}
